// pages/technology-integral/technology-integral.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        store_id: null,
        option: [{
                text: '全部',
                value: 0
            },
            {
                text: '门店确认',
                value: 1
            },
            {
                text: '平台确认',
                value: 2
            },
            {
                text: '审核通过',
                value: 3
            },
            {
                text: '门店作废',
                value: 4
            },
            {
                text: '平台作废',
                value: 5
            },
        ],
        page: 1,
        list: [],
        show: false,
        value: 0,
        desc: "",
        noMore: false,
        fileList: [],
        images: [],
    },
    deleteHandle(event) {
        const {
            index
        } = event.detail;

        const {
            fileList,
            images
        } = this.data;
        fileList.splice(index, 1);
        images.splice(index, 1);
        this.setData({
            fileList,
            images,
        });
    },
    afterReadHandle(event) {
        const file = event.detail.file;

        const {
            fileList,
            images
        } = this.data;

        wx.showLoading({
            title: "上传中...",
        });
        wx.ajax.uploadFile({
            filePath: file.url,
            callback: (url) => {
                wx.hideLoading();
                if (url) {
                    fileList.push(file);
                    images.push(url);
                    this.setData({
                        fileList,
                        images,
                    });
                }
            },
        });
    },

    getList() {},

    valueChange({
        detail
    }) {
        this.setData({
            page: 1,
            value: detail,
            list: [],
        })
        this.getList()
    },

    handleAdd() {
        this.setData({
            desc: "",
            show: true,
            fileList: [],
            images: [],
        })
    },

    onClose() {
        this.setData({
            show: false
        })
    },

    handleAddSubmit() {
        const reg = /^\d+$/
        let {
            desc,
            store_id,
            fileList
        } = this.data

        if (!desc) {
            wx.showToast({
                title: "请输入申请内容",
                icon: 'none'
            })
            return
        }

        wx.ajax.post("addScoreApply.action", {
            desc,
            file_ids: fileList.map(item => item.url).join(","),
            merchant_info_id: store_id,
        }, true).then((res) => {
            if (res.success) {
                this.setData({
                    show: false
                })
            } else {
                wx.showToast({
                    title: "新增失败",
                    icon: 'none'
                })
            }
        })

    },

    getValue({
        detail,
        target
    }) {
        this.setData({
            [target.id]: detail
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let {
            store_id
        } = options
        this.setData({
            store_id
        })

        this.getList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})